package com.springcloud.servicehi.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author chenkuan
 * @version v1.0
 * @desc
 * @date 2019/4/25 025 13:02
 */
@Slf4j
@RestController
public class HelloController {

	@Autowired
	private RestTemplate restTemplate;

	@Value("${server.port}")
	private String port;

	@RequestMapping("/hi")
	public String home(String name) {
		log.info("hi " + name + " ,i am from port:" + port);
		return "hi " + name + " ,i am from port:" + port;
	}

	@RequestMapping("/himiya")
	public String callHome(String name) {
		log.info("calling trace service-hi to service-miya");
		return restTemplate.getForObject("http://localhost:8763/miya?name=" + name, String.class);
	}

	@RequestMapping("/info")
	public String info(String name) {
		log.info("hello " + name);
		log.info("trace service-miya callback");
		return "hello " + name + " i'm service-hi";
	}

}
